package org.example.carsystem.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.carsystem.domain.SysPost;
import org.example.carsystem.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/post")
@CrossOrigin
public class PostController {
    @Autowired
    private PostService postService;

    @GetMapping("/select")
    public Map<String,Object> postSelect(@RequestParam(value = "postCode",required = false)String postCode,
                                         @RequestParam(value = "postName",required = false)String postName,
                                         @RequestParam(value = "status",required = false)String status,
                                         @RequestParam("pageNum")Integer pageNum,@RequestParam("pageSize")Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<SysPost> list = postService.postSelect(postCode,postName,status);
        PageInfo<Object> info = new PageInfo<>(list);
        Map<String, Object> map = new HashMap<>();
        map.put("code",200);
        map.put("list",info);
        return map;
    }

    @GetMapping("/select/All")
    public Map<String,Object> PostSelectAll(){
       return postService.PostSelectAll();
    }
}
